![]() | CONTINUED FRACTIONS |
r | a | √r |
2 | 1 | √2 = 1 + 1/(1 + √2) |
2 | 2 | √2 = 2 + (−2)/(2 + √2) |
2 | 3 | √2 = 3 + (−7)/(3 + √2) |
2 | 4 | √2 = 4 + (−14)/(4 + √2) |
n1
/n2
is as follows:
〈( quotients(n1 n2) =
( (s = ()) // result sequence to be returned (initially, empty)
(m1° = n1) // initial numerator
(m2° = n2) // initial denominator
( (mc° = m1÷m2) // quotient
(s° = (s↓ mc) // include quotient in result
(mr° = m1 − m2*mc) // remainder
(mr = 0) → ¡s // if remainder is zero, return result
(m1° = m2) // new numerator
(m2° = mr) // new denominator
)☆
)!
)〉
quotients(179 42) // ev. (4 3 1 4 2)
n1
, n2
) of the equivalent rational number.
Cociente | Valor |
2 | v=2 |
4 | v = 4 +1/v = 4 + 1/2 = 9/2 |
1 | v = 1 + 1/v = 1 + 2/9 = 11/9 |
3 | v = 3 + 1/v = 3 + 9/11 = 42/11 |
4 | v = 4 + 1/v = 4 + 11/42 = 179/42 |
〈( fraction(quotients) =
( (i° = quotients#) // number of quotients
(nc° = quotients) // initial quotient
(nr1° = nc) // initial numerator of result
(nr2° = 1) // initial denominator of the result
( (i° = i-1) // point to previous quotient
(i=0 → ¡(nr1 nr2)) // if end of quotients, return result
(n1° = nr1) // new denominator
(n2° = nr2)
(nc° = quotient) // new quotient
(nr1° = nc + n1) // new numerator of the result
(nr2 = n2) // new result denominator
)★
)!
)〉
fraction(4 3 1 5 11) // ev. (179 42)